package com.example.mall.web.controller;

import com.example.mall.domain.OrderRefunds;
import com.example.mall.dto.OrderRefundsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.OrderRefundsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IOrderRefundsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderRefunds")
public class OrderRefundsController {

    @Autowired
    public IOrderRefundsService orderRefundsService;

    /**
     * 分页查询订单退款表信息
     * @param orderRefundsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询订单退款表信息",notes = "分页查询订单退款表信息",httpMethod = "GET")
    public JSONResult queryPage(OrderRefundsQuery orderRefundsQuery){
        PageDTO<OrderRefundsDto> orderRefundsDtoPageDTO = orderRefundsService.queryPage(orderRefundsQuery);
        return JSONResult.success("查询成功",orderRefundsDtoPageDTO);
    }

    /**
     * 根据id查询订单退款表信息
     * @param refundId
     * @return
     */
    @GetMapping("query/{refundId}")
    @ApiOperation(value = "根据id查询订单退款表信息",notes = "根据id查询订单退款表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("refundId")Long refundId){
        //1.根据id查询用户信息
        if (refundId == null){
            throw new GlobalCustomerException(ErrorEnumCode.REFUNDID_NOT_ID);
        }
        OrderRefunds orderRefunds = orderRefundsService.getById(refundId);
        return JSONResult.success("查询成功",orderRefunds);
    }

    /**
     * 根据id查询订单退款表信息
     * @param refundId
     * @return
     */
    @GetMapping("queryOrderRefundsById/{refundId}")
    @ApiOperation(value = "根据id查询订单退款表信息",notes = "根据id查询订单退款表信息",httpMethod = "GET")
    public JSONResult queryOrderRefundsById(@PathVariable("refundId")Long refundId){
        //1.根据id查询用户信息
        if (refundId == null){
            throw new GlobalCustomerException(ErrorEnumCode.REFUNDID_NOT_ID);
        }
        OrderRefunds orderRefunds = orderRefundsService.queryOrderRefundsById(refundId);
        return JSONResult.success("查询成功",orderRefunds);
    }

    /**
     * 查询全部订单退款表信息
     * @param
     * @return
     */
    @GetMapping("queryOrderRefundsList")
    @ApiOperation(value = "查询全部订单退款表信息",notes = "查询全部订单退款表信息",httpMethod = "GET")
    public JSONResult queryOrderRefundsList(){
        List<OrderRefunds> orderRefunds = orderRefundsService.queryOrderRefundsList();
        return JSONResult.success("查询成功",orderRefunds);
    }

    /**
     * 新增订单退款表
     * @param orderRefundsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增订单退款表",notes = "新增订单退款表",httpMethod = "POST")
    public JSONResult insert(@RequestBody OrderRefundsDto orderRefundsDto){
        orderRefundsService.insert(orderRefundsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改订单退款表信息
     * @param orderRefundsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改订单退款表信息",notes = "修改订单退款表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody OrderRefundsDto orderRefundsDto){
        orderRefundsService.update(orderRefundsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除订单退款表信息
     * @param refundId
     * @return
     */
    @PostMapping("delete/{refundId}")
    @ApiOperation(value = "删除订单退款表信息",notes = "删除订单退款表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("refundId") Long refundId) {
        orderRefundsService.delete(refundId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除订单退款表信息
     * @param refundIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除订单退款表信息",notes = "批量删除订单退款表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> refundIds) {
        orderRefundsService.deleteBatch(refundIds);
        return JSONResult.success("批量删除成功");
    }
}
